In [74]:
library(MASS)
require(graphics)
library(Cairo)


Error in library(Cairo): there is no package called ‘Cairo’
Traceback:

1. library(Cairo)
2. stop(txt, domain = NA)

In [50]:
data <- read.table("apple.txt",
                   sep="",
                   col.names=c("Variety", "FusariumStrain", "Days", "AppleWeight",
                               "Radius", "FungalRadialAdvance", "RateOfAdvance"))
data$Variety = as.factor(data$Variety)
data$FusariumStrain = as.factor(data$FusariumStrain)

In [51]:
data


VarietyFusariumStrainDaysAppleWeightRadiusFungalRadialAdvanceRateOfAdvance
1 1 70 156.2 3.66 2.04 0.0291
1 2 70 153.9 3.65 1.23 0.0176
1 3 70 137.8 3.51 1.25 0.0179
1 4 70 141.0 3.53 1.66 0.0237
1 5 70 145.8 3.58 1.74 0.0249
1 6 70 147.8 3.60 1.88 0.0269
1 7 70 174.9 3.81 2.26 0.0323
2 1 103 91.3 3.07 1.16 0.0113
2 2 103 115.5 3.05 1.26 0.0122
2 3 103 99.5 3.15 0.41 0.0040
2 4 103 101.2 3.17 2.39 0.0232
2 5 103 106.8 3.23 2.01 0.0195
2 6 103 88.1 3.03 1.98 0.0192
2 7 103 100.2 3.16 2.26 0.0219
3 1 54 66.5 2.66 2.29 0.0424
3 2 54 67.6 2.68 1.02 0.0189
3 3 54 64.8 2.64 0.27 0.0050
3 4 54 59.3 2.57 2.63 0.0487
3 5 54 70.1 2.71 2.58 0.0478
3 6 54 68.1 2.69 2.11 0.0391
3 7 54 64.0 2.63 2.73 0.0506
4 1 138 68.7 2.74 1.46 0.0106
4 2 138 66.7 2.71 0.53 0.0038
4 3 138 72.4 2.78 0.05 0.0004
4 4 138 68.6 2.74 1.69 0.0122
4 5 138 68.0 2.73 1.60 0.0116
4 6 138 62.2 2.65 2.15 0.0156
4 7 138 73.1 2.79 1.67 0.0121
5 1 89 62.7 2.46 1.33 0.0149
5 2 89 60.6 2.44 0.59 0.0066
5 3 89 67.8 2.53 0.60 0.0067
5 4 89 64.4 2.44 1.95 0.0219
5 5 89 54.5 2.35 1.76 0.0198
5 6 89 57.4 2.40 1.25 0.0140
5 7 89 60.9 2.44 2.05 0.0230

In [52]:
nrow(data)


35

In [53]:
data$RateOfAdvance


  1. 0.0291
  2. 0.0176
  3. 0.0179
  4. 0.0237
  5. 0.0249
  6. 0.0269
  7. 0.0323
  8. 0.0113
  9. 0.0122
  10. 0.004
  11. 0.0232
  12. 0.0195
  13. 0.0192
  14. 0.0219
  15. 0.0424
  16. 0.0189
  17. 0.005
  18. 0.0487
  19. 0.0478
  20. 0.0391
  21. 0.0506
  22. 0.0106
  23. 0.0038
  24. 4e-04
  25. 0.0122
  26. 0.0116
  27. 0.0156
  28. 0.0121
  29. 0.0149
  30. 0.0066
  31. 0.0067
  32. 0.0219
  33. 0.0198
  34. 0.014
  35. 0.023

In [54]:
round(data$FungalRadialAdvance / data$Days, 4) == data$RateOfAdvance


  1. TRUE
  2. TRUE
  3. TRUE
  4. TRUE
  5. TRUE
  6. TRUE
  7. TRUE
  8. TRUE
  9. TRUE
  10. TRUE
  11. TRUE
  12. TRUE
  13. TRUE
  14. TRUE
  15. TRUE
  16. TRUE
  17. TRUE
  18. TRUE
  19. TRUE
  20. TRUE
  21. TRUE
  22. TRUE
  23. TRUE
  24. TRUE
  25. TRUE
  26. TRUE
  27. TRUE
  28. TRUE
  29. TRUE
  30. TRUE
  31. TRUE
  32. TRUE
  33. TRUE
  34. TRUE
  35. TRUE

Exploratory Analysis

Histograms for Apple Weight and Apple Radius


In [72]:
# 1. Open jpeg file
#jpeg("histograms.jpg", width = 750, height = 350)
svg(filename="histograms.svg", 
    width=5, 
    height=4, 
    pointsize=12)

# 2. Create the plot
par(mfrow=c(1, 2))
hist(data$AppleWeight, cex.axis=0.9, cex.lab=1.2, main="", xlab="Apple Weight (g)")
hist(data$Radius, cex.axis=0.9, cex.lab=1.2, main="", xlab="Apple Radius (cm)")

# 3. Close the file
dev.off()


Warning message in svg(filename = "histograms.svg", width = 5, height = 4, pointsize = 12):
“unable to load shared object '/usr/local/Cellar/r/3.5.1/lib/R/library/grDevices/libs//cairo.so':
  dlopen(/usr/local/Cellar/r/3.5.1/lib/R/library/grDevices/libs//cairo.so, 6): image not found”Warning message in svg(filename = "histograms.svg", width = 5, height = 4, pointsize = 12):
“failed to load cairo DLL”
null device: 1

In [70]:
# 1. Open jpeg file
jpeg("boxplots.jpg", width = 1200, height = 800)

# 2. Create the plot
par(mfrow=c(1, 3))

boxplot(AppleWeight~Variety, data=data, main="", cex.axis=0.9, cex.lab=1.2, 
   xlab="Apple Variety", ylab="Apple Weight (g)")
boxplot(RateOfAdvance~FusariumStrain, data=data, main="", cex.axis=0.9, cex.lab=1.2, 
   xlab="Fusarium Strain", ylab="Rate of Advance")
plot.design(RateOfAdvance ~ FusariumStrain + Variety, data=data, main="", cex.axis=0.9, cex.lab=1.2)

# 3. Close the file
dev.off()


pdf: 2

In [64]:
# 1. Open jpeg file
jpeg("boxplots.jpg", width = 750, height = 600)

# 2. Create the plot
with(data, interaction.plot(x.factor=Variety, trace.factor = FusariumStrain,
                            cex.axis=0.9, cex.lab=1.2, 
                            response=RateOfAdvance, fun=mean, legend=T, ylab="Rate of Advance", col=2:8))

# 3. Close the file
dev.off()


pdf: 2

Fungal Radial Advance models

Most complex model.


In [130]:
model_fra <- aov(FungalRadialAdvance ~ Variety * FusariumStrain * AppleWeight * Days, data=data)

In [131]:
summary(model_fra)


                                        Df Sum Sq Mean Sq F value  Pr(>F)   
Variety                                  1  0.778   0.778   1.537 0.23023   
FusariumStrain                           1  4.344   4.344   8.578 0.00861 **
AppleWeight                              1  0.417   0.417   0.824 0.37550   
Days                                     1  0.670   0.670   1.322 0.26442   
Variety:FusariumStrain                   1  0.028   0.028   0.054 0.81812   
Variety:AppleWeight                      1  0.039   0.039   0.076 0.78570   
FusariumStrain:AppleWeight               1  0.158   0.158   0.312 0.58274   
Variety:Days                             1  0.008   0.008   0.015 0.90355   
FusariumStrain:Days                      1  0.025   0.025   0.049 0.82714   
AppleWeight:Days                         1  0.007   0.007   0.013 0.91048   
Variety:FusariumStrain:AppleWeight       1  0.050   0.050   0.098 0.75727   
Variety:FusariumStrain:Days              1  0.000   0.000   0.000 0.99207   
Variety:AppleWeight:Days                 1  0.526   0.526   1.039 0.32076   
FusariumStrain:AppleWeight:Days          1  0.006   0.006   0.012 0.91305   
Variety:FusariumStrain:AppleWeight:Days  1  0.000   0.000   0.000 0.98994   
Residuals                               19  9.621   0.506                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

In [132]:
coef(model_fra)


(Intercept)
17.305584403028
Variety
-4.27936631848325
FusariumStrain
-0.0670350290326962
AppleWeight
-0.169951280951447
Days
-0.219579225748811
Variety:FusariumStrain
-0.351116907038438
Variety:AppleWeight
0.0411890659847118
FusariumStrain:AppleWeight
0.000778843061500377
Variety:Days
0.0751461165708688
FusariumStrain:Days
0.006564010997157
AppleWeight:Days
0.00262400108229716
Variety:FusariumStrain:AppleWeight
0.0067601297530425
Variety:FusariumStrain:Days
-0.00076070823573468
Variety:AppleWeight:Days
-0.000932361630757493
FusariumStrain:AppleWeight:Days
-0.00010362096336471
Variety:FusariumStrain:AppleWeight:Days
6.37279861512619e-06

In [133]:
layout(matrix(1:4,ncol=2)) 
plot(model_fra)


Basic model


In [134]:
model_fra_basic <- aov(FungalRadialAdvance ~ 1, data=data)

In [135]:
stepAIC(model_fra_basic, scope= ~ Variety * FusariumStrain * AppleWeight * Days)


Start:  AIC=-23.95
FungalRadialAdvance ~ 1

                 Df Sum of Sq    RSS     AIC
+ FusariumStrain  1    4.3437 12.332 -32.511
+ Days            1    1.3410 15.334 -24.884
<none>                        16.675 -23.950
+ Variety         1    0.7781 15.897 -23.622
+ AppleWeight     1    0.2000 16.475 -22.372

Step:  AIC=-32.51
FungalRadialAdvance ~ FusariumStrain

                 Df Sum of Sq    RSS     AIC
+ Days            1    1.3410 10.991 -34.541
+ Variety         1    0.7781 11.553 -32.793
<none>                        12.332 -32.511
+ AppleWeight     1    0.1965 12.135 -31.074
- FusariumStrain  1    4.3437 16.675 -23.950

Step:  AIC=-34.54
FungalRadialAdvance ~ FusariumStrain + Days

                      Df Sum of Sq    RSS     AIC
<none>                             10.991 -34.541
+ Variety              1    0.2511 10.739 -33.350
+ FusariumStrain:Days  1    0.0309 10.960 -32.639
+ AppleWeight          1    0.0276 10.963 -32.629
- Days                 1    1.3410 12.332 -32.511
- FusariumStrain       1    4.3437 15.334 -24.884
Call:
   aov(formula = FungalRadialAdvance ~ FusariumStrain + Days, data = data)

Terms:
                FusariumStrain      Days Residuals
Sum of Squares        4.343683  1.341000 10.990585
Deg. of Freedom              1         1        32

Residual standard error: 0.586051
Estimated effects may be unbalanced

In [136]:
best_model_fra = aov(formula = FungalRadialAdvance ~ FusariumStrain + Days, data = data)

In [137]:
summary(best_model_fra)


               Df Sum Sq Mean Sq F value Pr(>F)   
FusariumStrain  1  4.344   4.344  12.647 0.0012 **
Days            1  1.341   1.341   3.904 0.0568 . 
Residuals      32 10.991   0.343                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

In [138]:
coef(best_model_fra)


(Intercept)
1.5065299304708
FusariumStrain
0.176142857142857
Days
-0.00678053730852041

In [139]:
layout(matrix(1:4,ncol=2)) 
plot(best_model_fra)


Rate of Advance model


In [140]:
model_roa <- aov(RateOfAdvance ~ Variety * FusariumStrain * AppleWeight, data=data)

In [141]:
summary(model_roa)


                                   Df   Sum Sq   Mean Sq F value Pr(>F)  
Variety                             1 0.000443 0.0004425   3.653 0.0667 .
FusariumStrain                      1 0.000625 0.0006250   5.159 0.0313 *
AppleWeight                         1 0.000441 0.0004407   3.637 0.0672 .
Variety:FusariumStrain              1 0.000001 0.0000009   0.007 0.9332  
Variety:AppleWeight                 1 0.000911 0.0009113   7.522 0.0107 *
FusariumStrain:AppleWeight          1 0.000046 0.0000462   0.381 0.5422  
Variety:FusariumStrain:AppleWeight  1 0.000002 0.0000017   0.014 0.9059  
Residuals                          27 0.003271 0.0001211                 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

In [142]:
coef(model_roa)


(Intercept)
0.0288955951930812
Variety
0.0118605135436346
FusariumStrain
0.00760161796203462
AppleWeight
0.000118635005557201
Variety:FusariumStrain
-0.000576301760925512
Variety:AppleWeight
-0.00027634843293764
FusariumStrain:AppleWeight
-2.50949505328662e-05
Variety:FusariumStrain:AppleWeight
-7.6892897620657e-06

In [143]:
layout(matrix(1:4,ncol=2)) 
plot(model_roa)


AIC for models


In [126]:
model_roa_basic <- aov(RateOfAdvance ~ 1, data=data)

In [132]:
stepAIC(model_roa_basic, scope= ~Variety * FusariumStrain * AppleWeight)


Start:  AIC=-308.73
RateOfAdvance ~ Variety * FusariumStrain * AppleWeight

                                     Df  Sum of Sq       RSS     AIC
- Variety:FusariumStrain:AppleWeight  1 1.7247e-06 0.0032728 -310.71
<none>                                             0.0032710 -308.73

Step:  AIC=-310.71
RateOfAdvance ~ Variety + FusariumStrain + AppleWeight + Variety:FusariumStrain + 
    Variety:AppleWeight + FusariumStrain:AppleWeight

                                     Df  Sum of Sq       RSS     AIC
- FusariumStrain:AppleWeight          1 0.00004616 0.0033189 -312.22
- Variety:FusariumStrain              1 0.00006937 0.0033421 -311.98
<none>                                             0.0032728 -310.71
+ Variety:FusariumStrain:AppleWeight  1 0.00000172 0.0032710 -308.73
- Variety:AppleWeight                 1 0.00093324 0.0042060 -303.93

Step:  AIC=-312.22
RateOfAdvance ~ Variety + FusariumStrain + AppleWeight + Variety:FusariumStrain + 
    Variety:AppleWeight

                             Df  Sum of Sq       RSS     AIC
- Variety:FusariumStrain      1 0.00002363 0.0033426 -313.97
<none>                                     0.0033189 -312.22
+ FusariumStrain:AppleWeight  1 0.00004616 0.0032728 -310.71
- Variety:AppleWeight         1 0.00091127 0.0042302 -305.73

Step:  AIC=-313.97
RateOfAdvance ~ Variety + FusariumStrain + AppleWeight + Variety:AppleWeight

                             Df  Sum of Sq       RSS     AIC
<none>                                     0.0033426 -313.97
+ Variety:FusariumStrain      1 0.00002363 0.0033189 -312.22
+ FusariumStrain:AppleWeight  1 0.00000042 0.0033421 -311.98
- FusariumStrain              1 0.00047839 0.0038209 -311.29
- Variety:AppleWeight         1 0.00088851 0.0042311 -307.72
Call:
   aov(formula = RateOfAdvance ~ Variety + FusariumStrain + AppleWeight + 
    Variety:AppleWeight, data = data)

Terms:
                    Variety FusariumStrain AppleWeight Variety:AppleWeight
Sum of Squares  0.000442514    0.000624983 0.000440673         0.000888508
Deg. of Freedom           1              1           1                   1
                  Residuals
Sum of Squares  0.003342556
Deg. of Freedom          30

Residual standard error: 0.0105555
Estimated effects may be unbalanced

In [128]:
best_model_roa <- aov(formula = RateOfAdvance ~ FusariumStrain + Variety + AppleWeight + 
    Variety:AppleWeight, data = data)

In [129]:
summary(best_model_roa)


                    Df   Sum Sq   Mean Sq F value  Pr(>F)   
FusariumStrain       1 0.000625 0.0006250   5.609 0.02450 * 
Variety              1 0.000443 0.0004425   3.972 0.05544 . 
AppleWeight          1 0.000441 0.0004407   3.955 0.05592 . 
Variety:AppleWeight  1 0.000889 0.0008885   7.975 0.00835 **
Residuals           30 0.003343 0.0001114                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

In [130]:
coef(best_model_roa)


(Intercept)
0.0522105607927795
FusariumStrain
0.00185845754319811
Variety
0.00904381319086793
AppleWeight
7.58216427951966e-06
Variety:AppleWeight
-0.000297500551810858

In [131]:
layout(matrix(1:4,ncol=2)) 
plot(best_model_roa)



In [ ]: